<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="80px">

      <el-form-item label="订单号" prop="orderNum">
        <el-input
          v-model="queryParams.orderNum"
          placeholder="请输入订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="付款方" prop="proxyName" label-width="85px">
        <el-input
          v-model="queryParams.publicName"
          placeholder="请输入付款方"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8" v-if="this.rolesKey == '00' ">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:record:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordList">
      <el-table-column label="订单号" align="center" prop="orderNum"/>

      <el-table-column label="商品名称" align="center" prop="goodName"/>
      <el-table-column label="付款方" align="center" prop="publicName"/>
      <el-table-column label="收款方" align="center" prop="proxyName"/>
      <el-table-column label="返利金额" align="center" prop="rebateAmount"/>
      <el-table-column label="交易金额" align="center" prop="totalAmount"/>
      <el-table-column label="创建时间" align="center" prop="createTime"/>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listRecord } from '@/api/acting/record'
import { downLoadExcel } from '@/utils/download'
import { mapState } from 'vuex'

export default {
  name: 'Record',
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 分销返利记录表格数据
      recordList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      //分销详情列表
      recordDetail: [],
      //id的名称
      roleId: '商家id',
      // 表单校验
      rules: {
        subRole: [
          { required: true, message: '1代理商给代理商 2 商家给代理商不能为空', trigger: 'blur' }
        ],
        goodId: [
          { required: true, message: '商品id不能为空', trigger: 'blur' }
        ],
        orderNum: [
          { required: true, message: '订单号不能为空', trigger: 'blur' }
        ],
        userId: [
          { required: true, message: '用户id不能为空', trigger: 'blur' }
        ],
        publicId: [
          { required: true, message: '如果role为1 折此字段是代理商id 2此字段为商家id不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  computed: {
    ...mapState({
      rolesKey: (state) => state.user.rolesKey
    })
  },
  methods: {
    /** 查询分销返利记录列表 */
    getList() {
      this.loading = true
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    // cancel() {
    //   this.open = false;
    //   this.reset();
    // },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        subRole: undefined,
        goodName: undefined,
        goodId: undefined,
        totalAmount: undefined,
        orderNum: undefined,
        userId: undefined,
        publicName: undefined,
        rebateAmount: undefined,
        publicId: undefined,
        createTime: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10
      }
      this.handleQuery()
    },
    /** 导出按钮操作 */
    handleExport() {
      downLoadExcel('/system/branch/record/export', this.queryParams)
    }
  }
}
</script>
